<extend name="./public/frame.html"/>
<block name="content">
    活动名称：
    <div class="layui-inline"><input type="text" class="layui-input" id="recharge_name" style="width: 150px;" placeholder="活动名称"></div>
    活动时间：
    <div class="layui-inline"><input type="text" class="layui-input" id="start" style="width: 150px;" placeholder="开始时间"></div>
    <div class="layui-inline"><input type="text" class="layui-input" id="end" style="width: 150px;" placeholder="结束时间"></div>
    活动状态
    <div class="layui-inline">
        <select id="status" name="status" class="layui-input" lay-filter="status" style="width: 150px;">
            <option value="">选择状态</option>
            <option value="1">未开始</option>
            <option value="2">进行中</option>
            <option value="3">已结束</option>
        </select>
    </div>
    <div class="layui-inline">
        <button class="layui-btn" id="search" data-type="search">搜索</button>
    </div>
    <div class="layui-inline">
        <a class="layui-btn layui-btn-normal newsAdd_btn" data-url="{:url('Promotion/add')}" onclick="add_t(this,'添加活动')">添加活动</a>
    </div>
    <div class="layui-inline">
        <a class="layui-btn layui-btn-normal newsAdd_btn" data-url="{:url('Promotion/activity')}"
           onclick="add_t(this,'添加充值配置')">充值配置</a>
    </div>
    <table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('Promotion/recharge')}', page: true, limit: 10, id:'test'}" lay-filter="test">
        <thead>
        <tr>
            <th lay-data="{field:'recharge_id', width:70, fixed: true, align:'center'}">ID</th>
            <th lay-data="{field:'recharge_name', width:150, align:'center'}">活动名称</th>
            <th lay-data="{field:'money', width:120,align:'center'}">充值金额（元）</th>
            <th lay-data="{field:'money_return', width:120,align:'center'}">赠送金额（元）</th>
            <th lay-data="{field:'region_name',width:200,align:'center'}">活动城市</th>
            <th lay-data="{field:'start_time', width:160,align:'center'}">开始时间</th>
            <th lay-data="{field:'end_time', width:160,align:'center'}">结束时间</th>
            <th lay-data="{field:'status',  width:100,align:'center'}">活动状态</th>
            <!--<th lay-data="{field:'status',  width:100}">状态</th>
            <th lay-data="{field:'comment', width:120}">描述</th>-->
            <th lay-data="{field:'audit_status', width:100,align:'center'}">审核状态</th>
            <th lay-data="{field:'admin_name', width:100,align:'center'}">操作人</th>
            <th lay-data="{field:'time', width:160,align:'center'}">创建时间</th>
            <th lay-data="{field:'update_time', width:160,align:'center'}">更新时间</th>
            <th lay-data="{fixed:'right', toolbar: '#barDemo', width:250, align:'center'}">操作</th>
        </tr>
        </thead>
    </table>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit" style="width: 50px">修改</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" style="width: 50px">删除</a>
        <?php if($admin_info['admin_type'] == 1){ ?>
        <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="recharge_audit" style="width: 50px">审核</a>
        <?php } ?>
    </script>
    <script>
        layui.use(['table','laydate'], function () {
            var table = layui.table,laydate = layui.laydate;
            laydate.render({
                elem: '#start' //指定元素
                ,type: 'datetime'
                ,theme: '#393D49'
            });
            laydate.render({
                elem: '#end' //指定元素
                ,type: 'datetime'
                ,theme: '#393D49'
            });
            //搜索
            $('#search').on('click', function () {
                var recharge_name 	= $("#recharge_name").val();
                var start_time 	    = $("#start").val();
                var end_time 	    = $("#end").val();
                var status		    = $("#status").val();
                 table.reload('test', {
                     url: '/admin/Promotion/recharge', where: {
                         "recharge_name": recharge_name,
                         "start_time": start_time,
                         "end_time": end_time,
                         "status": status,
                     }
                 });
            });
            $(document).on('click', '.layui-btn', function () {
                var type = $(this).data('type');
                if (type == 'add') {
                    window.location = "{:url('add')}";
                }
            });
            //监听工具条
            table.on('tool(test)', function (obj) {
                var data = obj.data;
                var recharge_id = data.recharge_id;
                if (obj.event === 'del') {
                    layer.confirm('确定删除吗?', function (index) {
                        var url = "{:url('del')}";
                        $.post(url, {'recharge_id': recharge_id}, function (res) {
                            switch (res['status']){
                                case 1:
                                    window.location.reload();
                                    break;
                                default:
                                    layer.alert(res['msg'],{icon: 5});
                                    break;
                            }
                        }, 'json');
                        layer.close(index);
                    });
                }else if (obj.event === 'recharge_audit') {
                    layer.confirm('确定审核通过吗?', function (index) {
                        var url = "{:U('recharge_audit')}";
                        $.post(url, {'recharge_id': recharge_id}, function (data) {
                            console.log(data);
                            if(data.status == 1){
                                layer.msg(data.msg,{'icon':1});
                                setTimeout(function (){
                                    window.location.reload();
                                }, 1000);
                            }else{
                                layer.msg(data.msg,{'icon':2});
                            }
                        }, 'json');
                        layer.close(index);
                        window.location.reload();
                    });
                }else if (obj.event === 'edit') {
                    layer.open({
                        type: 2,
                        title: '编辑活动',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{:url("edit","recharge_id=")}' + recharge_id //iframe的url
                    });
                }
            });
        });
    </script>
</block>
